package com.ag.lwc.action;
import java.util.Set;
import javax.annotation.Resource;

import com.ag.common.BaseAction;
import com.ag.contactTree.TreeNode;
import com.ag.contactTree.service.LocalTreeService;
import com.ag.zhh.service.ContactService;
import com.ag.zhh.service.OADeptService;
import com.ag.zhh.vo.UserDept;
import com.ag.zhh.vo.UserDeptContact;
//OA通信录的查询
public class OAContactAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5844048965203127777L;
	private String treeNodeId;				//OA通信录树的结点
	private Set<UserDeptContact> oaContactlist;			//OA通信录的联系人列表,查询用
	private String message;
	private LocalTreeService treeService;

	private UserDept dept;							//部门
	private String leader;		//负责人id
	private String leaderName; 	//	负责人名
	private ContactService contactService;
	private OADeptService deptService;

	/**
	 * 返回到去OA通信录的界面
	 */
	public String execute()
	{
		//contacts = contactdao
		return "OAContact";
	}
	//设定负责人
	public String designLeader()
	{
		//获取部门
		try {
			UserDept dept = (UserDept)treeService.getTreeNodeById(treeNodeId).getBindData();
			UserDeptContact user =contactService.findCotnactByCId(leader);
			System.out.println(user.getUName());
			dept.setTbUser(user);
			deptService.updateDept(dept);
			message="success";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "leader";
	}


	
	
	/**
	 * 获取OA部门的通信录,弹回到OA通信录的右边的界面
	 * @return
	 */
	public String findOAContactByDept()
	{
		TreeNode node=null;
		 dept = null;
		System.out.println("OACointactAction:  OA树的结点： "+treeNodeId);
		try{		
			node = treeService.getTreeNodeById(treeNodeId);		//通过数的id查部门结点
			if(node==null) return "findContact";
			System.out.println("OA部门的id："+node.getNodeId());
			 dept = (UserDept)node.getBindData();
			 System.out.println("OA通信录树的id："+dept.getUdId()+" OA");
			 oaContactlist = dept.getTbUsers();
			 //获取负责人
			 if(dept.getTbUser()!=null)
			 {
				 leader=dept.getTbUser().getUId();
			 	leaderName = dept.getTbUser().getUName();
			 }
		}catch(Exception e){e.printStackTrace();}	
		
		//测试是否拿到联系人
		if(oaContactlist!=null)
		{
			System.out.println("size: "+oaContactlist.size());;
			for(UserDeptContact user:oaContactlist){
				System.out.println("   用户id："+user.getUId()+" 用户名："+user.getUName()+" 用户电话："+user.getUTel()+"  用户手机："+user.getUPhone());
			}
		}
		else System.out.println("没有联系人 size: ");
			return "findContact";
	}

	public String getTreeNodeId() {
		return treeNodeId;
	}

	public void setTreeNodeId(String treeNodeId) {		
		this.treeNodeId = treeNodeId;
		System.out.println("能不能拿到: treeNodeId: "+this.treeNodeId);
	}

	public Set<UserDeptContact> getOaContactlist() {
		return oaContactlist;
	}

	public void setOaContactlist(Set<UserDeptContact> oaContactlist) {
		this.oaContactlist = oaContactlist;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public LocalTreeService getTreeService() {
		return treeService;
	}


	public void setTreeService(LocalTreeService treeService) {
		this.treeService = treeService;
	}




	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public UserDept getDept() {
		return dept;
	}




	public void setDept(UserDept dept) {
		this.dept = dept;
	}




	public String getLeader() {
		return leader;
	}




	public void setLeader(String leader) {
		this.leader = leader;
	}




	public String getLeaderName() {
		return leaderName;
	}




	public void setLeaderName(String leaderName) {
		this.leaderName = leaderName;
	}
	public ContactService getContactService() {
		return contactService;
	}
	public void setContactService(ContactService contactService) {
		this.contactService = contactService;
	}
	public OADeptService getDeptService() {
		return deptService;
	}
	public void setDeptService(OADeptService deptService) {
		this.deptService = deptService;
	}


}
